<!--
Copyright (c) 2019, salesforce.com, inc.
All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
-->
<html>
<head>
    <script type="text/javascript">
        document.write("<base href='/" + window.location.pathname.split('/')[1] + "/' />");
    </script>
    <script src="webfiles/debug.js"></script>
    <script src="webfiles/sloop_ui.js"></script>
    <title>Sloop Debug Query Badger</title>
    <link rel='shortcut icon' type='image/x-icon' href='webfiles/favicon.ico' />
</head>
<body onload="loadHomeRef();"> 
[ <a id="homeLink">Home</a> ][ <a href="debug/">Debug Menu</a> ]<br/>

<h2>Query Sloop's Badger DB Directly</h2>

<table bgcolor="silver" width="500px"><tr><td style="padding: 20px">
<form action="debug/listkeys/" method="get">
    <label for="table">Table Name:</label><br/>
    <select name="table" id="table">
        <option value="watch">watch</option>
        <option value="ressum">ressum</option>
        <option value="eventcount">eventcount</option>
        <option value="watchactivity">watchactivity</option>
        <option value="internal">internal</option>
        <option value="all">all</option>
    </select><br><br>

    <input type="radio" id="regex" name="searchOption" value="regex" onchange="queryChange(this)" checked>
    <label for="regex">Query by Regex</label>
    <input type="radio" id="partition" name="searchOption" value="partition" onchange="queryChange(this)">
    <label for="partition">Query by Time</label><br><br>

    <div class="regex">
        <label for="keymatch">Key RegEx Filter:</label><br>
        <input type="text" name="keymatch" id="keymatch"><br><br>
    </div>

    <div class="partition" style="display:none">
        <label for="lookback">Look Back Range:</label><br/>
        <select name="lookback" id="lookback">
            <option value="1">1 Hour</option>
            <option value="3">3 Hours</option>
            <option value="6">6 Hours</option>
            <option value="12">12 Hours</option>
            <option value="24">1 Day</option>
            <option value="168">1 Week</option>
            <option value="336">2 Weeks</option>
        </select><br><br>

        <label for="urlmatch">Key Search:{Kind/Namespace/Name} </label><br/>
        <input type="text" name="urlmatch" id="urlmatch"><br><br>
    </div>

    <label for="maxrows">Max Rows:</label><br>
    <input type="text" name="maxrows" id="maxrows"><br><br>

    <input type="submit">
</form>
</td></tr></table>
<br/><br/>

<table border="1">
    <tr><td>Total Keys Matched</td><td>{{.KeysMatched}}</td></tr>
    <tr><td>Total Size of Matched Keys</td><td><pre>{{.TotalSize}}</pre></td></tr>
    <tr><td>Total Keys Searched</td><td><pre>{{.TotalKeys}}</pre></td></tr>
</table>
<br/><br/><br/>
<b>Key List</b>:<br/>
<ol>
    {{range $key, $value := .Keys}}
        <li><a href='debug/view?k={{.}}'>{{.}}</a>
    {{end}}
</ol>
</body>

<script src="webfiles/filter.js"></script>
<script>
    setText("maxrows", "maxrows", "1000")
    setDropdown("table", "table", "watch")
    setText("keymatch", "keymatch", ".*")
    setDropdown("lookback", "lookback", "1")
    setText("urlmatch", "urlmatch", "/")
    setRadio("searchOption", "searchOption", "regex")
</script>
</html>
